
<template name='goods_card'>
	<view class="box-infos font12  " >
		<!-- 列表区 -->
		<view class="content-box " >
			<view class="boxsss100" >
				<view class="top-but menu-scroll-w" >
					<view class="top-but-box">
						<text selectable="true"  class="tipss">用于若要使用卡密则必须在【分组线路】->【价格分组中】中设置某个分组个销售分组；</text>
						<button
						v-if="typeName!='card'"
						@click="AddLevelCard()"
						class="leftBut color5" 
						>
							生成会员卡密
						</button>
						
						<button
						v-if="typeName=='card'"
						@click="AddCard()"
						class="leftBut color5" 
						>
							生成积分卡密(仅可充值余额)
						</button>
						
						<button @click="$common.noMultipleClicks('GetLevelCard',GetLevelCard,true)"
						class="leftBut color1" 
						>
							<img src="../../static/img/search.png" class="ico" ></img>
							刷新
						</button>
					</view>
				</view>
				<table v-if="list &&  list.length>0">
					<!-- 表头 -->
					<thead>
						<tr >
							<th  class="centers " style="min-width: 20px;">
								序号
							</th>
							<th  >
								卡密
							</th>
							<th  class="centers ">
								复制状态
							</th>
							<th  class="centers ">
								使用状态
							</th>
							<th  class="centers ">
								操作
							</th>
						</tr>
					</thead>
					<tbody>
						<!-- 内容 -->
						<tr  
						:key="index" 
						@click="TabcheckedIndex=index"
						v-for="(item,index) in list" 
						:class="TabcheckedIndex == index ? 'goods-list-select':''"
						>
							<td  class="centers ">
								{{index+1}}
							</td>
							<td   class="">
								<text :selectable="true">{{item.card}}</text>
							</td>
							<td class="centers" >
								<view class="flex gap10">
									<view class="add_color search-but " @click="UpdateLevelCard(item.id,index)">复制</view>	
									<text class="justify">{{item.mode==0 ? '':'已复制'}}</text>
									
								</view>
							</td>
							<td   class="centers" :class="item.status==1 ?'money_color':''">
								<view class="flex gap10 centers">
									<text class="justify">{{item.status==0 ? '未使用':'已使用'}}</text>
									
								</view>
							</td>
							<td   class="alter centers" @click="DeleteLevelCard(item.id,index)">
								删除
							</td>
						</tr>
					</tbody>
				</table>
				<!-- 暂无数据 -->
				<empty v-if="list &&  list.length==0"></empty>
				<!-- end -->
			</view>
		</view>
		<!-- end -->
	</view>
</template>

<script>
	import empty from "@/components/admin-components/empty.vue"
	export default{
		name:'goods_card',
		components: {
			empty,
		},
		data(){
			return{
				TabcheckedIndex:-1,//当前选中项
				list:[],
			}
		},
		 // 此处定义传入的数据
		props: {
	
			typeName: {
				type:String ,
				default: 'month'//month|year|card
			},//卡密的天数
		},
		created() {
			this.GetLevelCard(true)
		},
		methods:{
			//获取列表
			GetLevelCard(){
				var that = this
				that.$common.get_request(
					{
						type:'GetLevelCard',
						typeName:this.typeName
					},
					(res)=>{
						that.list = res.list
					}
				);
			},
			
			//修改、复制
			UpdateLevelCard(id,index){
				var that = this
				that.$common.get_request(
					{
						type:'UpdateLevelCard',
						id: id,
					},
					(res)=>{
						that.list[index].mode = 1 
						that.$set(that.list,index,that.list[index])
						that.$common.setClipboardData(that.list[index].card)
					}
				);
			},
			//删除
			DeleteLevelCard(id,index){
				var that = this
				that.$common.get_request(
					{
						type:'DeleteLevelCard',
						id: id,
					},
					(res)=>{
						that.list.splice(index,1)
						that.$common.toast(res.msg)
					}
				);
			},
			//添加
			AddLevelCard(){
				var that = this
				uni.showModal({
					title:'请输入欲要生成的卡密数量',
					mask:true,
					editable:true,
					placeholderText:'1',
					success:(res)=>{
						if(res.confirm ){
							if(res.content.length==0){
								that.$common.showModal('提示',"未输入内容")
								return
							}
							var count = res.content.trim();
							var value = count.split("\n");  
							that.$common.get_request(
								{
									type:'AddLevelCard',
									count:value,
									typeName:that.typeName
								},
								(e)=>{
									that.$common.toast(e.msg)
									that.GetLevelCard()
								}
							);
						}
					}
				})
			},
		
			//添加
			AddCard(){
				var that = this
				uni.showModal({
					title:'请输入欲要生成的卡密数量',
					mask:true,
					editable:true,
					placeholderText:'1',
					success:(res)=>{
						if(res.confirm ){
							if(res.content.length==0){
								that.$common.showModal('提示',"未输入内容")
								return
							}
							var count = res.content.trim();
							count = count.split("\n");  
							
							uni.showModal({
								title:'请输入卡密的金额数值',
								mask:true,
								editable:true,
								placeholderText:'1',
								success:(res)=>{
									if(res.confirm ){
										if(res.content.length==0){
											that.$common.showModal('提示',"未输入内容")
											return
										}
										var money = res.content.trim();
										money = money.split("\n");  
										
										
										that.$common.get_request(
											{
												type:'AddLevelCard',
												count:count,
												money:money,
												typeName:that.typeName
											},
											(e)=>{
												that.$common.toast(e.msg)
												that.GetLevelCard()
											}
										);
									}
								}
							})
						}
					}
				})
			},
					
		}
	}
</script>

<style>
</style>
